#include "CRotateCommand.h"
#include "CUserInterface.h"
#include "CLevelEditor.h"
#include "ISceneManager.h"
#include "ISceneNode.h"
#include "CSceneObject.h"

extern CGlobals* g;
extern CUserInterface* ui;
extern CLevelEditor* editor;

CRotateCommand::CRotateCommand (int id, quaternion oldRotation, quaternion newRotation)
{
	m_id = id;
	m_oldRotation = oldRotation;
	m_newRotation = newRotation;
	stringw name = editor->getSceneObjectFromID(id)->m_UserData->getAttributeAsStringW("Name");
	setDescription(stringw(L"rotate ") + name + L"(" + stringw(id) + L")");
}

void CRotateCommand::redo ()
{
	core::vector3df rotate;
	m_newRotation.toEuler(rotate);
	g->sceneManager->getSceneNodeFromId(m_id)->setRotation(rotate);
}

void CRotateCommand::undo ()
{
	core::vector3df rotate;
	m_oldRotation.toEuler(rotate);
	g->sceneManager->getSceneNodeFromId(m_id)->setRotation(rotate);
}
